// Future-Get.cpp : 
// 
// 这个程序主要是想展示 std::future 的用法
// 以及std::future.get()的用法

#include <iostream>
#include <future>

//#include "TestHeaders.h"

int find_the_answer_to_ltuae() {
    std::cout << "find the answer" << std::endl;
    return 0;
}

void do_other_stuff() {
    std::cout << "do other stuff!" << std::endl;
}

//int testFutureGet()

int main()
{
    std::future<int> the_answer = std::async(find_the_answer_to_ltuae);
    std::future<int> future_left = std::async([=]() {
        std::cout << "left robot is running" << std::endl;
        return 0;
        });
    std::future<int> future_right = std::async([=]() {
        std::cout << "right robot is running" << std::endl;
        return 0;
        });
    
    do_other_stuff();
    
    std::cout << "The answer is " << the_answer.get() << std::endl;     
    // future::get() 等待线程执行结束并返回线程函数的返回值

    if (future_left.get() == 0 && future_right.get() == 0)
        std::cout << "Dual Robot process successed!" << std::endl;
    else
        std::cout << "Dual Robot process failed!" << std::endl;
    return 0;
}
